package com.example.designsoft.basetest;

import java.lang.ref.WeakReference;

/**
 * author : Gyk
 * time   : 2020/11/18
 * todo   :
 */
public abstract class BasePresenter<M, V> {

    public  M mModel;
    public  V mView;
    private WeakReference<V> mWeakRf;

    public void onAttachModelAndView(M model, V view) {
        mWeakRf = new WeakReference<V>(view);
        this.mModel = model;
    }

    public V getView() {
        if (isAttach()) {
            return mWeakRf.get();
        } else {
            return null;
        }
    }

    public boolean isAttach() {
        return mWeakRf != null && mWeakRf.get() != null;
    }

    public void onDettach() {
        if (mWeakRf != null) {
            mWeakRf.clear();
            mWeakRf = null;
        }
    }

}
